const { $Message } = require('../../dist/base/index');
const handler = require("../../utils/function.js");
// pages/service/bankcard-binding/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bankArr: [],
    bank:"",
    bankaccount :"",
    bankname:"",
    getmoney:""
  },
  bindBankChange: function (e) {
    var that = this;
    console.log(e)
    that.setData({
      bank: that.data.bankArr[e.detail.value]
    });
  },
  changeInputData: function (e) {
    var that = this;
    var inputName = e.currentTarget.dataset.name;
    var inputVlaue = e.detail.value;
    if (inputName == "bank") {
      console.log(inputVlaue)
      that.setData({
        bank: inputVlaue
      });
    }
    if (inputName == "bankName") {
      that.setData({
        bankname: inputVlaue
      });
    }
    if (inputName == "bankAccount") {
      that.setData({
        bankaccount: inputVlaue
      });
    }
    if (inputName == "getmoney") {
      that.setData({
        getmoney: inputVlaue
      });
    }
  },
  onShow:function(){
    var that=this;
    handler.requestData("lookBank", {}, function (res) {
      if (res.success == true) {
        that.setData({
          bankArr: res.data
        })

      }
    });

    // app.request({
    //   url: api.wallet.bankcard,
    //   method:'post',
    //   data:{
    //   },
    //   success:function(e){
    //     that.setData({
    //       bankArr:e.data
    //     })
    //   }
    // })
    
  
  },
  sendRequest: function () {
    var that = this;
    if (that.validate()) {
      // TODO 发送请求
      var that = this;
      var para = {
        user_id:wx.getStorageSync('user_info').id,
        bankid: that.data.bank.title,
        name: that.data.bankname,
        bank_number: that.data.bankaccount,
        getmoney: that.data.getmoney
      };
      handler.requestData("applyWithdrawal", para, function (res) {
        if (res.success == true) {
          // $Message({
          //   content: '提交成功请等待审核',
          //   type: 'success'
          // });
          wx.showToast({
            title:'提交成功,待审核',
            icon: 'loading'
          })
        
        } else {
          wx.showToast({
            title: res.message,
            icon:'loading'
          })
          // $Message({
          //   content: res.message,
          //   type: 'error'
          // });
        }
      });
    }
  },
  validate: function () {
    var that = this;

    if (!that.data.bank || that.data.bank == '') {
      wx.showToast({
        title: '请选择开户行',
        icon: 'none',
        mask: true,
      });
      return false;
    }
    if (!that.data.bankname || that.data.bankname == '') {
      wx.showToast({
        title: '开户人不得为空',
        icon: 'none',
        mask: true,
      });
      return false;
    }
    if (!that.data.bankaccount || that.data.bankaccount == '') {
      wx.showToast({
        title: '账号不得为空',
        icon: 'none',
        mask: true,
      });
      return false;
    }
    if (!that.data.getmoney || that.data.getmoney == '') {
      wx.showToast({
        title: '金额不得为空',
        icon: 'none',
        mask: true,
      });
      return false;
    }
    return true;
  },
 
})